package main
import (
	"fmt"
	"github.com/garyburd/redigo/redis"
	"strconv"
)

func main(){
	conn,err := redis.Dial("tcp","127.0.0.1:6379")
	if err != nil {
		fmt.Println("Redis Connect Error : ",err)
		return 
	}
	defer conn.Close() //及时关闭处理
	var name,age,skill string
	for i:=1;i<=3;i++{
		fmt.Printf("开始录入第%d个妖怪信息！|\n",i)
		fmt.Printf("请输入妖怪名字：")
		fmt.Scanln(&name)
		fmt.Printf("请输入妖怪年龄：")
		fmt.Scanln(&age)
		fmt.Printf("请输入妖怪技能：")
		fmt.Scanln(&skill)
		
		_,err := conn.Do("HMSet","Monster"+strconv.Itoa(i),"name",name,"age",age,"skill",skill)
		if err != nil{
			fmt.Println("存入数据失败！")
			return 
		}else{
			fmt.Printf("第%d个妖怪信息录入成功！\n\n",i)
		}
	}
	fmt.Println("妖怪信息录入完毕！\n所录妖怪信息如下：")
	for i:=1;i<=3;i++{
		str,err := redis.Strings(conn.Do("HMGet","Monster"+strconv.Itoa(i),"name","age","skill"))
		if err != nil {
			fmt.Println("妖怪信息读取失败!")
		}

		fmt.Printf("\n第%d个妖怪的信息：\n",i)
		fmt.Println("name\tage\tskill")
		for _,v := range str{
			fmt.Printf("%v\t",v)
		}
	}
}